<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends Action {
    public function index(){
        header("Content-Type:text/html; charset=utf-8");
		if(session ( 'username'))
			$this->redirect("home");
		else
			$this->display();
    }
	public function logout() {
		
		session ( null );
		$this->display ( "index" );
	}
	public function home(){
        header("Content-Type:text/html; charset=utf-8");
		if(session ( 'uid'))
		{
			$this->display();
		}
		else
		{
		$Dao = M ( "User" );
		if ($Dao->create ()) {
			$condition ['username'] = $Dao->username;
			$condition ['password'] = MD5 ( $Dao->password );
			// 查询数据
			$list = $Dao->where ( $condition )->find ();
			if ($list) {
				//echo '账号正确';
				session(array('expire'=>10));
				session ( 'uid', $list ['uid'] );
				session ( 'username', $list ['username'] );
				session ( 'nickname', $list ['nickname'] );
				session ( 'depart', $list ['depart'] );
				$this->display();
			} else {
				$this->error ( "账号/密码错误" );
			
			}
		}
		else if(!session('uid')){
			$this->error ( "尚未登陆！" );
		}
		}
		
		
		
        
    }
	public function timer(){			
					
		$condition ['getname'] = session('nickname');		
		$condition ['state'] = 0;		
		
		$Dao=D("Mail");
		
		$total = $Dao->where ( $condition )->count ();
		if($total!=0)		
		$list["new"] = "yes";
		else
		$list["new"] = "no";
		
		$Data = json_encode($list);
		print_r($Data);
	}
	public function news(){
		$condition ['getname'] = session('nickname');		
		$condition ['state'] = 0;		
		
		$Dao=D("Mail");
		
		$total = $Dao->where ( $condition )->count ();

		if($total!=0)	
			 $this->assign("newmail", "newmail");

		$this->display();
	}
	
}